package com.mx.project.controller;

import com.mx.project.common.exception.CodeEnum;
import com.mx.project.common.exception.JKException;
import com.mx.project.common.util.JWTService;
import com.mx.project.pojo.User;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@Api(tags = "用于测试的controller")
@RestController
@RequestMapping
public class HelloController {

    @Autowired
    private JWTService jwtService;

    @RequestMapping("token")
    public User token(HttpServletRequest request){
        String token = request.getHeader("token");
        User user = null;
        if(user == null){
            throw new JKException(CodeEnum.ILLEGAL_TOKEN);
        }
        return user;
    }

    @RequestMapping("xss1")
    public String testXSS(String name){
        return name;
    }
    @RequestMapping("xss2")
    public User testXSS(@RequestBody User user){
        return user;
    }

}
